import Page
from Page import App
from Base.Base import Base
from selenium.webdriver.common.by import By


class AppDownloadListPage(Base):
    """
    车应用下载列表页
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 下载列表标题
        self.download_title_text = (By.XPATH, Page.TEXT.format("下载列表"))

        # 列表应用的封面, 默认取1
        self.download_list_app_cover_img = (By.XPATH, App.download_list_app_cover_img.format(1))

        # 列表列用的应用名, 默认取1
        self.download_list_app_name_text = (By.XPATH, App.download_list_app_name_text.format(1))

        # 列表应用的取消按钮. 默认取1
        self.download_list_app_cancel_btn = (By.XPATH, App.download_list_app_cancel_btn.format(1))

        # 列表应用的下载按钮. 默认取1
        self.download_list_app_download_btn = (By.XPATH, App.download_list_app_download_btn.format(1))

        # 列表应用的版本号. 默认取1
        self.download_list_app_version_text = (By.XPATH, App.download_list_app_version_text.format(1))

        # 列表应用的网速. 默认取1
        self.download_list_app_network_text = (By.XPATH, App.download_list_app_network_text.format(1))

        # 列表应用的下载进度条. 默认取1
        self.download_list_app_progress_bar = (By.XPATH, App.download_list_app_progress_bar.format(1))

    def get_list_app_cover(self, index=1):
        """
        获取指定索引的封面

        :param index: 索引值
        :return:
        """
        self.download_list_app_cover_img = (By.XPATH, App.download_list_app_cover_img.format(index))
        return self.find_element_o(self.download_list_app_cover_img)

    def get_list_app_name(self, index=1):
        """
        获取指定索引的应用名

        :param index: 索引值
        :return:
        """
        self.download_list_app_name_text = (By.XPATH, App.download_list_app_name_text.format(index))
        return self.find_element_o(self.download_list_app_name_text)

    def get_list_app_cancel(self, index=1):
        """
        获取指定索引的取消按钮

        :param index: 索引值
        :return:
        """
        self.download_list_app_cancel_btn = (By.XPATH, App.download_list_app_cancel_btn.format(index))
        return self.find_element_o(self.download_list_app_cancel_btn)

    def get_list_app_download(self, index=1):
        """
        获取指定索引的下载按钮

        :param index: 索引值
        :return:
        """
        self.download_list_app_download_btn = (By.XPATH, App.download_list_app_download_btn.format(index))
        return self.find_element_o(self.download_list_app_download_btn)

    def get_list_app_version(self, index=1):
        """
        获取指定索引的应用版本

        :param index: 索引值
        :return:
        """
        self.download_list_app_version_text = (By.XPATH, App.download_list_app_version_text.format(index))
        return self.find_element_o(self.download_list_app_version_text)

    def get_list_app_network(self, index=1):
        """
        获取指定索引的下载网速

        :param index: 索引值
        :return:
        """
        self.download_list_app_network_text = (By.XPATH, App.download_list_app_network_text.format(index))
        return self.find_element_o(self.download_list_app_network_text)

    def get_list_app_progress(self, index=1):
        """
        获取指定索引的下载进度条

        :param index: 索引值
        :return:
        """
        self.download_list_app_progress_bar = (By.XPATH, App.download_list_app_progress_bar.format(index))
        return self.find_element_o(self.download_list_app_progress_bar)

    def click_list_app_cancel(self, index=1):
        """
        点击指定索引的取消下载按钮

        :param index: 索引值
        :return:
        """
        self.download_list_app_cancel_btn = (By.XPATH, App.download_list_app_cancel_btn.format(index))
        self.click_element(self.download_list_app_cancel_btn)
